package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.LabelInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-19
 * @Description:
 * @Version: 1.0
 */
@Tag(name="标签管理")
@RestController
@RequestMapping("/admin/label")
public class LabelInfoController {

    @Autowired
    private LabelInfoService labelInfoService;

    @Operation(summary = "根据类型查询标签列表")
    @GetMapping("list")
    public Result<List<LabelInfo>> list(@RequestParam(required = false) ItemType type){
        LambdaQueryWrapper<LabelInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(type!=null,LabelInfo::getType, type);
        List<LabelInfo> list = labelInfoService.list(wrapper);
        return  Result.ok(list);
    }

    @Operation(summary = "保存或更新标签信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LabelInfo labelInfo){
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.ok();
    }

    @Operation(summary = "根据id删除标签信息")
    @DeleteMapping("deleteById")
    public Result deleteById(@RequestParam Long id){
        labelInfoService.removeById(id);
        return Result.ok();
    }
}
